package com.jinxin.platform.cdelecinspect.rpc;

import com.jinxin.platform.base.common.annotation.RegBusiness;
import com.jinxin.platform.base.common.pojo.JsonResult;
import com.jinxin.platform.cdelecinspect.constant.Constants;
import com.jinxin.platform.cdelecinspect.mapper.pojo.*;
import com.jinxin.platform.cdelecinspect.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * All rights Reserved, Designed By www.beonelot.com
 *
 * @version: V1.0
 * @Copyright: www.beonelot.com Inc. All rights reserved.
 * @Description：
 * @Date: 2020-04-05
 * @Author: Lingnan
 **/
@RegBusiness(moduleKey = Constants.MODULE_KEY, className = "EleinspectRpcService")
public class EleinspectRpcService {
    @Autowired
    private EleinspectTaskService eleinspectTaskService;
    @Autowired
    private EleinspectMappingPointLineService eleinspectMappingPointLineService;
    @Autowired
    private EleinspectMappingPointItemsService eleinspectMappingPointItemsService;
    @Autowired
    private EleinspectRecordService eleinspectRecordService;
    @Autowired
    private EleinspectItemsRecordService eleinspectItemsRecordService;

    //根据巡检人员id查询任务
    public JsonResult getTasksByStaffId(Map param) {
        HashMap<String, Object> paramMap = new HashMap<>();
        String staffId = String.valueOf(param.get("staffId"));
        if (StringUtils.isEmpty(staffId)){
            return JsonResult.error("人员id不能为null");
        }
        paramMap.put("staffId",staffId);
        List<EleinspectTask> list = eleinspectTaskService.list(paramMap);
        if (list.isEmpty()){
            return JsonResult.error("该巡检人员暂无任务");
        }else{
            return JsonResult.ok("成功",list);

        }
    }

    //根据线路id查询点位
    public JsonResult getPointsByLineId(Map param) {
        HashMap<String, Object> paramMap = new HashMap<>();
        String lineId = String.valueOf(param.get("lineId"));
        if (StringUtils.isEmpty(lineId)){
            return JsonResult.error("线路id不能为null");
        }
        paramMap.put("mappingLineId",lineId);
        List<EleinspectMappingPointLine> list = eleinspectMappingPointLineService.list(paramMap);
        if (list.isEmpty()){
            return JsonResult.error("该线路暂无点位");
        }else{
            return JsonResult.ok("成功",list);
        }
    }

    //根据点位id查询项目
    public JsonResult getItemsByPointId(Map param) {
        HashMap<String, Object> paramMap = new HashMap<>();
        String pointId = String.valueOf(param.get("pointId"));
        if (StringUtils.isEmpty(pointId)){
            return JsonResult.error("点位id不能为null");
        }
        paramMap.put("mappingPointId",pointId);
        List<EleinspectMappingPointItems> list = eleinspectMappingPointItemsService.list(paramMap);
        if (list.isEmpty()){
            return JsonResult.error("该点位暂无项目");
        }else{
            return JsonResult.ok("成功",list);
        }
    }


    //根据任务id查询点位记录
    public JsonResult getPointRecordListByTaskId(Map param) {
        HashMap<String, Object> paramMap = new HashMap<>();
        String recordTaskId = String.valueOf(param.get("taskId"));
        if (StringUtils.isEmpty(recordTaskId)){
            return JsonResult.error("任务id不能为null");
        }
        paramMap.put("recordTaskId",recordTaskId);
        List<EleinspectRecord> list = eleinspectRecordService.list(paramMap);
        if (list.isEmpty()){
            return JsonResult.error("无数据");
        }else{
            return JsonResult.ok("成功",list);
        }
    }

    //根据点位记录id查询项目记录
    public JsonResult geItemsRecordListByRecordId(Map param) {
        HashMap<String, Object> paramMap = new HashMap<>();
        String itemPointRecordId = String.valueOf(param.get("recordId"));
        if (StringUtils.isEmpty(itemPointRecordId)){
            return JsonResult.error("记录id不能为空");
        }
        paramMap.put("itemPointRecordId",itemPointRecordId);
        List<EleinspectItemRecord> list = eleinspectItemsRecordService.list(paramMap);
        if (list.isEmpty()){
            return JsonResult.error("无数据");
        }else{
            return JsonResult.ok("成功",list);
        }
    }

}
